# 通过APIRouter可以模块化管理路由，并将其包含到主应用中
from fastapi import FastAPI
from fastapi import APIRouter
import uvicorn

app = FastAPI()

router = APIRouter()
# 主应用路由
@app.get('/me/{user_id}')
def get_current_user(user_id: int):
    return {"user_id": user_id}

# 子路由
@router.get('/users')
async def read_users():
    return ["Rick", "Morty", "Summer"]

app.include_router(router)  # 将路由包含到主应用中

if __name__ == '__main__':
    uvicorn.run(app, host="127.0.0.1", port=8000)
